home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / hinge / hui.c < prev    next >
C/C++ Source or Header  |  1992-11-10  |  5KB  |  254 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/time.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #include "ooglutil.h"
  7. #include "3d.h"
  8. #include "hinge.h"
  9. #include "hui.h"
  10. #include "version.h"
  11.  
  12. int mainplacement = FL_PLACE_MOUSE;
  13. int helpplacement = FL_PLACE_MOUSE;
  14. int infoplacement = FL_PLACE_MOUSE;
  15. int fileplacement = FL_PLACE_MOUSE;
  16.  
  17. char hingehelpstr[] =
  18. #include "hingehelp.h"
  19. ;
  20.  
  21. static char *getline(char *s);
  22.  
  23. hui_init()
  24. {
  25.   char buf[120];
  26.  
  27.   foreground();
  28.   create_the_forms();
  29.   
  30.   sprintf(buf, "%1g", angle);
  31.   fl_set_input(AngleInput, buf);
  32.   
  33.   fl_add_browser_line(SpaceBrowser, "Euclidean");
  34.   fl_add_browser_line(SpaceBrowser, "Hyperbolic");
  35. #if 0
  36.   fl_add_browser_line(SpaceBrowser, "Spherical");
  37. #endif
  38.   switch (space) {
  39.   case EUCLIDEAN:
  40.     fl_select_browser_line( SpaceBrowser, 1 );
  41.     break;
  42.   case HYPERBOLIC:
  43.     fl_select_browser_line( SpaceBrowser, 2 );
  44.     break;
  45.   case SPHERICAL:
  46.     fl_select_browser_line( SpaceBrowser, 3 );
  47.     break;
  48.   }
  49.   
  50.   {
  51.     FILE *hf = fopen("hingehelp", "r");
  52.  
  53.     if (hf == NULL) {
  54.       char *line, *delims = "\n";
  55.       line = getline(hingehelpstr);
  56.       while (line) {
  57.     fl_add_browser_line( HelpBrowser, line );
  58.     line = getline(NULL);
  59.       }
  60.       fl_set_browser_topline( HelpBrowser, 1 );
  61.     } else {
  62.       if (hf != NULL) {
  63.     while (fgets(buf, 120, hf) != NULL)
  64.       fl_add_browser_line( HelpBrowser, buf );
  65.     fl_set_browser_topline( HelpBrowser, 1 );
  66.     fclose(hf);
  67.       }
  68.     }
  69.   }
  70. }
  71.  
  72. hui_main_loop()
  73. {
  74.   int fdmask;
  75.   static struct timeval timeout = {0, 200000};
  76.  
  77.   if (mainplacement == FL_PLACE_POSITION) {
  78.     fl_set_form_position(MainForm, mainpos[0], mainpos[1]);
  79.   }
  80.   if (fileplacement == FL_PLACE_POSITION) {
  81.     fl_set_form_position(FileForm, filepos[0], filepos[1]);
  82.   }
  83.   if (helpplacement == FL_PLACE_POSITION) {
  84.     fl_set_form_position(HelpForm, helppos[0], helppos[1]);
  85.   }
  86.   if (infoplacement == FL_PLACE_POSITION) {
  87.     fl_set_form_position(InfoForm, infopos[0], infopos[1]);
  88.   }
  89.  
  90.   {
  91.     char buf[20];
  92.     sprintf(buf, "Hinge %s", HINGE_VERSION);
  93.     fl_set_object_label(MainFormLabel, buf);
  94.     fl_set_object_label(InfoFormLabel, buf);
  95.   }
  96.  
  97.   fl_show_form(MainForm, mainplacement, TRUE, "Hinge");
  98.  
  99.   while (1) {
  100.  
  101.     fdmask = 1 << fileno(stdin);
  102.     select(fileno(stdin)+1, &fdmask, NULL, NULL, &timeout);
  103.  
  104.     if (async_fnextc(stdin,0) != NODATA) {
  105.       Input();
  106.     }
  107.     fl_check_forms();
  108.   }
  109. }
  110.  
  111. void SpaceBrowserProc(FL_OBJECT *obj, long val)
  112. {
  113.   int line = fl_get_browser(obj);
  114.   switch (line) {
  115.   case 1:
  116.     HingeSpace(EUCLIDEAN);
  117.     break;
  118.   case 2:
  119.     HingeSpace(HYPERBOLIC);
  120.     break;
  121.   case 3:
  122.     HingeSpace(SPHERICAL);
  123.     break;
  124.   }
  125. }
  126.  
  127.  
  128. void QuitProc(FL_OBJECT *obj, long val)
  129. {
  130.   if (killgv) {
  131.     fprintf(togv, "(quit)\n");
  132.     fflush(togv);
  133.   }
  134.   exit(0);
  135. }
  136.  
  137.  
  138. void FileButtonProc(FL_OBJECT *obj, long val)
  139. {
  140.   int winid;
  141.   winid = fl_show_form(FileForm,fileplacement,TRUE,"Hinge File");
  142. }
  143.  
  144.  
  145. void FileCancelButtonProc(FL_OBJECT *obj, long val)
  146. {
  147.   fl_hide_form(FileForm);
  148. }
  149.  
  150.  
  151. void FileOKButtonProc(FL_OBJECT *obj, long val)
  152. {
  153.   char *str = fl_get_input(FileInput);
  154.  
  155.   if (HingeLoad(str))
  156.     fl_hide_form(FileForm);
  157. }
  158.  
  159. void FileInputProc(FL_OBJECT *obj, long val)
  160. {
  161.   /*noop*/
  162. }
  163.  
  164. void UndoButtonProc(FL_OBJECT *obj, long val)
  165. {
  166.   Undo();
  167. }
  168.  
  169. void
  170. hui_message(char *s)
  171. {
  172. #if 0
  173.   printf("message: %s\n",s);
  174. #endif
  175. }
  176.  
  177. extern void AngleInputProc(FL_OBJECT *obj, long val)
  178. {}
  179.  
  180. void InfoButtonProc(FL_OBJECT *obj, long val)
  181. {
  182.   int winid;
  183.   winid = fl_show_form(InfoForm,infoplacement,TRUE,"Hinge Info Window");
  184. }
  185.  
  186.  
  187.  
  188. void HelpButtonProc(FL_OBJECT *obj, long val)
  189. {
  190.   int winid;
  191.   winid = fl_show_form(HelpForm,helpplacement,TRUE,"Hinge Help Window");
  192. }
  193.  
  194.  
  195. void InfoOKButtonProc(FL_OBJECT *obj, long val)
  196. {
  197.   fl_hide_form(InfoForm);
  198. }
  199.  
  200.  
  201.  
  202. void HelpOKButtonProc(FL_OBJECT *obj, long val)
  203. {
  204.   fl_hide_form(HelpForm);
  205. }
  206.  
  207.  
  208. void ResetButtonProc(FL_OBJECT *obj, long val)
  209. {
  210.   Reset();
  211. }
  212.  
  213.  
  214. void HingeIt(int dir)
  215. {
  216.   float ang, initang, limit;
  217.   int instno;
  218.  
  219.   initang = 0;
  220.   angle = atof(fl_get_input(AngleInput));
  221.   limit = initang + angle;
  222.   
  223.   /* create a new inst */
  224.   instno = NewInst(initang);
  225.  
  226.   /* hinge the inst by steps of hingeincr up to limit */
  227.   for (ang=initang+hingeincr; ang<limit; ang += hingeincr) {
  228.     Inst(instno, (float)(dir * ang));
  229.   }
  230.   Inst(instno, (float)(dir * limit));
  231.  
  232. }
  233.  
  234.  
  235. static char *getline(char *s)
  236. {
  237.   static char *p;
  238.   char *first;
  239.  
  240.   if (s != NULL) {
  241.     p = s;
  242.   } else {
  243.     *p = '\n';
  244.   }
  245.   ++p;
  246.   first = p;
  247.   while (*p != '\n' && *p != '\0') ++p;
  248.   if (*p == '\n') {
  249.     *p = '\0';
  250.     return first;
  251.   }
  252.   return NULL;
  253. }
  254.